package cn.hzking.gjmall.adpters.gooddetail;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.bean.GoodDetailBean;

/**
 * Created by Administrator on 2018/3/9.
 */

public class GoodDetailPopAdapter extends BaseQuickAdapter<GoodDetailBean.DataBean.SkusBean, BaseViewHolder> {
    public GoodDetailPopAdapter(int layoutResId, @Nullable List<GoodDetailBean.DataBean.SkusBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodDetailBean.DataBean.SkusBean item) {
        TextView textView = helper.getView(R.id.gooddetail_pop_text);
        helper.addOnClickListener(R.id.gooddetail_pop_text);
        if (item.isWhetherActivite()) {//sku是活动
            if(item.getSnapupNumber() > 0){//活动的库存充足
                textView.setBackgroundResource(R.drawable.shape_gooddetail_pop_item_nomal);
            }else {//活动的库存不充足
                textView.setBackgroundResource(R.drawable.item_gooddetail_pop_item_unselected);
            }
            if(getData().size() ==1 && item.getSnapupNumber() >0){
                textView.setBackgroundResource(R.drawable.item_gooddetail_pop_item_selected);
            }

        } else {//sku不是活动
            if(item.getCurrentNumber() > 0){//正常的库存充足
                textView.setBackgroundResource(R.drawable.shape_gooddetail_pop_item_nomal);
            }else {//活动的库存不充足
                textView.setBackgroundResource(R.drawable.item_gooddetail_pop_item_unselected);
            }
            if(getData().size() ==1 && item.getCurrentNumber() >0){
                textView.setBackgroundResource(R.drawable.item_gooddetail_pop_item_selected);
            }
        }
        if(item.isSelected()){
            textView.setBackgroundResource(R.drawable.item_gooddetail_pop_item_selected);
        }
        textView.setText(String.valueOf(item.getSkuname()));

    }
}
